Skip to content

Conversation

@rubnogueira
Copy link

Background

Add inputCachedTokens to xai provider.

Summary

Include the cached_tokens variable as part of the inputCachedTokens.

Part of grok-4-fast response

      "usage": {
        "prompt_tokens": 2640,
        "completion_tokens": 182,
        "total_tokens": 3494,
        "prompt_tokens_details": {
          "text_tokens": 2640,
          "audio_tokens": 0,
          "image_tokens": 0,
          "cached_tokens": 473
        },
        "completion_tokens_details": {
          "reasoning_tokens": 672,
          "audio_tokens": 0,
          "accepted_prediction_tokens": 0,
          "rejected_prediction_tokens": 0
        },
        "num_sources_used": 0
      }

Manual Verification

  • pnpm build in this repo
  • Installed ai sdk 6.0.0-beta.68
  • Used generated package with grok-4-fast
  • .usage variable
{
  inputTokens: 555,
  outputTokens: 190,
  totalTokens: 1802,
  reasoningTokens: 1057,
  cachedInputTokens: 316,
}

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

N/A

Related Issues

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants